package com.xyh.transaction.controller;

import com.github.pagehelper.PageInfo;
import com.xyh.transaction.entity.dto.menu.MenuEditOrAddDto;
import com.xyh.transaction.entity.dto.menu.MenuSearchDto;
import com.xyh.transaction.entity.dto.user.ArrDto;
import com.xyh.transaction.entity.vo.MenuOptionsVO;
import com.xyh.transaction.response.ResponseResult;
import com.xyh.transaction.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@Api(tags = "前端菜单管理")
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @ApiOperation(value = "用户菜单列表", notes = "返回当前用户菜单列表")
    @GetMapping("/user_list")
    public ResponseResult<Set<MenuOptionsVO>> userMenuList() {
        Set<MenuOptionsVO> authMenuList = menuService.getAuthMenuList();
        return ResponseResult.success("查询成功！", authMenuList);
    }

    @ApiOperation(value = "菜单列表", notes = "返回所有菜单列表信息")
    @PostMapping("list")
    public ResponseResult<PageInfo<MenuOptionsVO>> list(@RequestBody MenuSearchDto menuSearchDto) {
        PageInfo<MenuOptionsVO> pageInfo = menuService.getMenuList(menuSearchDto);
        return ResponseResult.success("查询成功！",pageInfo);
    }

    @ApiOperation(value = "所有菜单路由",notes = "返回所有菜单路由id和title")
    @GetMapping ("all_list")
    public ResponseResult<List<MenuOptionsVO>> allList(){
        List<MenuOptionsVO> allMenu = menuService.getAllMenu();
        return ResponseResult.success("查询成功！",allMenu);
    }
    
    @ApiOperation(value = "修改菜单",notes = "根据id修改菜单信息")
    @PutMapping("edit")
    public ResponseResult<Void> edit (@RequestBody MenuEditOrAddDto menuEditOrAddDto) {
        menuService.updateMenu(menuEditOrAddDto);
        return ResponseResult.success("操作成功！",null);
    }

    @ApiOperation(value = "新增菜单",notes = "新增菜单信息")
    @PostMapping("add")
    public ResponseResult<Void> add (@RequestBody MenuEditOrAddDto menuEditOrAddDto) {
        menuService.addMenu(menuEditOrAddDto);
        return ResponseResult.success("操作成功！",null);
    }

    @ApiOperation(value = "删除菜单路由",notes = "根据id删除菜单路由")
    @PostMapping("delete")
    public ResponseResult<Void> delete(@RequestBody ArrDto arrDto){
        menuService.deleteMenu(arrDto);
        return ResponseResult.success("操作成功！",null);
    }


}
